<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间管理系统 - 测试页面</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .test-result { margin: 10px 0; padding: 10px; border-radius: 5px; }
        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
    </style>
</head>
<body>
    <h1>时间管理系统 - 模块加载测试</h1>
    <div id="test-results"></div>

    <script src="src/js/storage.js"></script>
    <script src="src/js/utils.js"></script>
    <script src="src/js/components.js"></script>
    <script>
        const results = document.getElementById('test-results');

        function addResult(message, type = 'info') {
            const div = document.createElement('div');
            div.className = `test-result ${type}`;
            div.textContent = message;
            results.appendChild(div);
        }

        // Test storage module
        try {
            if (typeof window.storage !== 'undefined') {
                addResult('✅ Storage 模块加载成功', 'success');

                // Test storage functionality
                const testRecord = {
                    date: '2024-01-01',
                    wakeTime: '07:00',
                    sleepTime: '23:00'
                };

                const added = storage.addSleepRecord(testRecord);
                if (added) {
                    addResult('✅ Storage 功能测试通过', 'success');
                    storage.deleteSleepRecord(added.id);
                } else {
                    addResult('❌ Storage 功能测试失败', 'error');
                }
            } else {
                addResult('❌ Storage 模块未加载', 'error');
            }
        } catch (error) {
            addResult(`❌ Storage 模块错误: ${error.message}`, 'error');
        }

        // Test utils module
        try {
            if (typeof window.Utils !== 'undefined') {
                addResult('✅ Utils 模块加载成功', 'success');

                // Test utils functionality
                const today = Utils.getToday();
                const formatted = Utils.formatDuration(2.5);
                addResult(`✅ Utils 测试: 今天是 ${today}, 2.5小时 = ${formatted}`, 'success');
            } else {
                addResult('❌ Utils 模块未加载', 'error');
            }
        } catch (error) {
            addResult(`❌ Utils 模块错误: ${error.message}`, 'error');
        }

        // Test components module
        try {
            if (typeof window.Components !== 'undefined') {
                addResult('✅ Components 模块加载成功', 'success');
            } else {
                addResult('❌ Components 模块未加载', 'error');
            }
        } catch (error) {
            addResult(`❌ Components 模块错误: ${error.message}`, 'error');
        }

        // Test localStorage
        try {
            localStorage.setItem('test', 'test');
            localStorage.removeItem('test');
            addResult('✅ localStorage 可用', 'success');
        } catch (error) {
            addResult('❌ localStorage 不可用', 'error');
        }

        addResult('测试完成！如果所有测试都显示 ✅，则系统可以正常工作。', 'info');

        // Add link to main app
        setTimeout(() => {
            const link = document.createElement('a');
            link.href = 'index.html';
            link.textContent = '🚀 前往主应用';
            link.style.display = 'inline-block';
            link.style.marginTop = '20px';
            link.style.padding = '10px 20px';
            link.style.background = '#007bff';
            link.style.color = 'white';
            link.style.textDecoration = 'none';
            link.style.borderRadius = '5px';
            document.body.appendChild(link);
        }, 1000);
    </script>
</body>
</html>